package com.myapp.util;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;

import com.myapp.R;
import com.myapp.ui.ShopDetailActivity;

public class MySimpleAdapter extends SimpleAdapter {
	
	private DisplayMetrics metrics;
	private Context context;
	private List<? extends Map<String, ?>> data;

	public MySimpleAdapter(Context context,List<? extends Map<String, ?>> data, int resource, String[] from,int[] to,DisplayMetrics metrics) {
		super(context, data, resource, from, to);
		this.context = context;
		this.metrics = metrics;
		this.data = data;
	}
	
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View v = super.getView(position, convertView, parent);
		ImageView img = (ImageView)v.findViewById(R.id.listview_shopImg);
		ScreenManager.setMyLayoutParam(img, ScreenManager.getWidth(0.38f, metrics), ScreenManager.getWidth(0.38f, metrics)/2 );
		LinearLayout ly_content = (LinearLayout)v.findViewById(R.id.listview_content);
		ScreenManager.setMyLayoutParam(ly_content, ScreenManager.getWidth(0.4f, metrics), img.getLayoutParams().height);
/*		img.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(context,ShopDetailActivity.class);
				Bundle b = new Bundle();
				b.putInt("shopid", Integer.parseInt(data.get(position).get("shopid").toString()));
				i.putExtras(b);
				context.startActivity(i);
			}
		});*/
		v.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(context,ShopDetailActivity.class);
				Bundle b = new Bundle();
				b.putInt("shopid", Integer.parseInt(data.get(position).get("shopid").toString()));
				i.putExtras(b);
				context.startActivity(i);
			}
		});
		return v;
	}
	
}
